home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6732 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  14.4 KB

  1. Path: Belgium.EU.net!box!pahint
  2. From: pahint@eunet.be (Pieter Hintjens)
  3. Newsgroups: comp.lang.c
  4. Subject: FYI: Libero 2.10 is available
  5. Date: 14 Feb 1996 17:59:10 GMT
  6. Organization: EUnet Belgium, Leuven, Belgium
  7. Message-ID: <4ft7te$89q@news.Belgium.EU.net>
  8. NNTP-Posting-Host: box.eunet.be
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.  
  12. Libero 2.11 is available for free downloading!
  13.  
  14. Point your browser to http://www.imatix.com for info.
  15.  
  16. Libero is a Programmer's Tool and Code Generator.  You define the
  17. high-level logic of a problem as a diagram: Libero generates the code
  18. to implement this logic.  Your applications are easier to write, more
  19. robust, easier to understand.  Libero uses a finite-state machine as
  20. underlying model.
  21.  
  22. Libero is multi-language, multi-platform, multi-purpose.  It uses
  23. a programmable code-generator engine and supports a wide range of
  24. languages:
  25.  
  26.     - C/C++
  27.     - Perl
  28.     - COBOL 74, COBOL 85
  29.     - Visual Basic, MS Test Basic 1.0
  30.     - UNIX C Shell, Korn Shell, Bourne Shell, Bash Shell
  31.     - 80x86 assembler
  32.     - Awk
  33.  
  34. Libero runs on these platforms:
  35.  
  36.     - UNIX (tested on Linux, HP/UX, SunOS, Irix 5.2, AIX 3.2.5, Solaris)
  37.     - MS-DOS
  38.     - MS-Windows
  39.     - Digital VAX/VMS and Open-VMS
  40.     - any (in principle) any platform with an ANSI C compiler.
  41.  
  42. Libero is free software following the GNU general public license.  This
  43. is an extract from the documentation:
  44.  
  45. ---------------------------------------------------------------------------
  46.  
  47.                                    Introduction
  48.  
  49.        "Laziness
  50.  
  51.           The quality  that makes  you go to great effort to reduce overall
  52.           energy expenditure.   It  makes you  write labour-saving programs
  53.           that other  people will  find useful, and document what you wrote
  54.           so you  don't have  to answer  so many questions about it.  Hence
  55.           the first great virtue of a programmer."
  56.  
  57.           - Larry Wall, Programming Perl.
  58.  
  59.  
  60.      How It All Started
  61.  
  62.        In 1982,  as a student, I got into games programming as a way of making
  63.      some money.  I skipped the build-it-yourself-from-an-old-TV-screen-and-a-
  64.      hex-keypad phase  of personal  computers, and  jumped straight  into  the
  65.      world of  ready-to-go colour  and sound.   My first PC had 5K of RAM, and
  66.      25x22 colour  video.   It could  beep in  three-part harmony.   My  first
  67.      published work  was an  article that  explained how  to tweak  the  video
  68.      output to  30x33 (hi  resolution!).   Soon I was writing sprite painters,
  69.      assembly libraries  for sound and graphics, even languages to replace the
  70.      built-in Basic.   Anything  to let  me write  my games faster and better.
  71.      Before I  knew what  had hit  me, I  was hooked into the cycle of writing
  72.      tools to improve the world I lived in.
  73.  
  74.        I haven't  written a  game for  a long time, but I've continued writing
  75.      tools.  Libero is one of the best - it's simple, clean, portable, and has
  76.      hit the mark so often that I feel it's unfair to keep it for myself.
  77.  
  78.        The ideas behind Libero evolved in Brussels, Belgium during the 1980's.
  79.      I worked with Leif Svalgaard, on what we would now call a CASE tool - ETK
  80.      - that  let COBOL programmers produce clean, portable code instead of the
  81.      mess we  generally saw.   One  of  the  key  techniques  we  used  was  a
  82.      programming method based on finite state machines.
  83.  
  84.        Historically, the  first real  programs that used finite state machines
  85.      were compilers.   Finite  state machines are also called Turing machines.
  86.      In 1967,  Peter Naur  describes a  new way  of using Turing machines in a
  87.      compiler, and shows how they simplify error checking.  He goes on to say:
  88.  
  89.        "The above  description has  stressed the checking aspect of the Turing
  90.      machine approach.   However, an equally important aspect is the ease with
  91.      which arbitrary  actions may  be specified.  (...) By using this approach
  92.      it is  usually possible  to  avoid  tests  in  individual  actions  to  a
  93.      surprisingly high degree.  This in our experience is a very effective way
  94.      of reducing the bulk and execution time of the translator algorithm."
  95.  
  96.        ETK provides  an interactive  editor that you use to describe the logic
  97.      of the  program as  a finite state machine.  This approach encourages you
  98.      to think  about the  complete problem.   You describe everything that can
  99.      happen, and  how the program should react.  The end-result looks a little
  100.      like a  flow-chart, but  has more  arrows, and  fewer different  kinds of
  101.      boxes.
  102.  
  103.        Now, in  a conventional  state machine,  these boxes are given numbers,
  104.      and the  programmer build  some tables  that encode  the arrows.  To make
  105.      such a  table by hand - or, just as bad, encode the table directly in the
  106.      logic of  the program,  using GOTOs - is a Bad Thing, since the result is
  107.      near to  impossible to  maintain.  The neat part of our solution was that
  108.      we took  the textual  description (called  a 'dialog'), and generated the
  109.      mystical tables  directly as COBOL code.  This is a Good Thing, since the
  110.      original dialog  is easy  to change,  and suddenly becomes excellent (and
  111.      always accurate) documentation.
  112.  
  113.        In 1992 I began working as a consultant, and found that I wanted to use
  114.      these techniques  in my  work.  I was writing in C, so I threw together a
  115.      code generator that could output C code using the same dialog methodology
  116.      I was used to.  I called this tool 'Libero' after the guy who runs around
  117.      the sidelines  at the football/soccer pitch doing all the dirty work.  My
  118.      first serious job was a bunch of TCP/IP clients and servers.  It was nice
  119.      to come  back to  the place  three years  later and  find  that  the  guy
  120.      maintaining my  work had only found one bug, and was happy to go into the
  121.      programs.   He said  that the  dialogs made  them easy  to understand and
  122.      modify.
  123.  
  124.        This kind  of experience convinced me that there was real value in this
  125.      tool.   I've written  lots of cute programs that are really useful for my
  126.      own needs,  but that  just don't  hack it  in the  real world.  Libero is
  127.      different.
  128.  
  129.        The first  release of  Libero generated C code using an external model,
  130.      called a  'schema'.   I had a couple of schemas; one for ANSI C code, and
  131.      one for multithreaded DEC/VMS code.
  132.  
  133.        I released  version 2.0  onto the  Net after  adding schemas  for  UNIX
  134.      scripts.  This release gave me a lot of feedback, and I rewrote the code-
  135.      generator again  to make it much more generic.  The current version has a
  136.      lot more  language schemas and a lot fewer bugs, plus a front-end for MS-
  137.      Windows.
  138.  
  139.        I hope  to continue in both these directions.  Libero has become a tool
  140.      that lets  you switch  between languages  at ease.   The first step is to
  141.      accept the state-machine as a valid method for program development.  This
  142.      takes a  little effort,  but I  hope that  the examples which follow will
  143.      help convince  you.   The second  step is  to see  that  this  method  is
  144.      language-independent.   You can write a program in Awk, then recode it in
  145.      C or Perl or assembler without changing its design.
  146.  
  147.  
  148.      Some Examples
  149.  
  150.        I've not  found a  quick way to convey the true nature of state machine
  151.      programming.   In my  experience, it  invariably  takes  a  few  days  of
  152.      practice.   After three  or four  days' exposure  to the  idea there is a
  153.      near-audible 'click!'  and something in the brain connects all the pieces
  154.      together and  you go  'Oh, it's  like THAT!'.   Maybe  people cultured on
  155.      event-driven programming will get it faster.
  156.  
  157.        In this  section  I'll  describe  some  everyday  situations  as  state
  158.      machines, in the hope that this will help the process.
  159.  
  160.  
  161.      Example 1: A Coke Machine
  162.  
  163.        The coke  machine (once  awake and  gently humming1)  sits against  the
  164.      wall, waiting.  Like all coke machines, it's very good at waiting, due to
  165.      Natural Selection.    All  the  impatient  proto-coke  machines  ran  off
  166.      screaming 'I  can't take  it anymore'  and  were  crunched  underfoot  by
  167.      brontosaurii back  in the  mists of  prehistory.  (I noted the part about
  168.      the mists  specifically to  explain why  the dinosaur trampled the proto-
  169.      coke machine  instead  of  extracting  something  cool  to  drink.    The
  170.      prevailing mists  also explain  the later  demise of the dinosaurs due to
  171.      extreme thirst.   The  surviving proto-coke machines moved patiently back
  172.      against the proto-walls, out of danger.)
  173.  
  174.      ____________________
  175.      1   There is  a theory  about  this,  notably  that  coke  machines  have
  176.      terrible memories,  and can't  remember the  words.   A second  school of
  177.      thought says  that the coke machines are humming because they're thinking
  178.      about all  the terrible  things they're  going to  do to humans with crow
  179.      bars.   A third  school of  thought reckons  that the  coke machines have
  180.      already done  something, and  are humming  because they  thought  it  was
  181.      really funny.
  182.  
  183.        A punter  arrives with  a handful  of loose  change.   The coke-machine
  184.      (covered by  the modern  and tasteful  metal grid  that serves  both as a
  185.      defensive covering and as an attraction for coke machines of the opposite
  186.      sex) moves into 'attention' mode.  When it hears the clink of tasty cash,
  187.      rather that the ominous clunk of a heavy crow-bar, it relaxes into 'ready
  188.      mode'.  The machine is now ready to handle any eventuality, so long as it
  189.      includes coinage.
  190.  
  191.        As the  last coin  falls and  the punter  presses the  button  labelled
  192.      'healthie  waye  sparkling  spring  water',  the  machine  considers  the
  193.      possibilities.   Should it  play dead,  and just take the punter's money?
  194.      Or maybe it can substitute a can of 30% sucrose 'sweeto-sap'?  Finally it
  195.      rumbles once,  then again for added effect, then excretes a can of water.
  196.      It munches the coins, then settles back against the wall, quietly humming
  197.      again.
  198.  
  199.        Just to  prove that  you can  describe any  sequence of events, however
  200.      improbable, with  a state  machine,  here  goes.   Act 1, scene 1 has our
  201.      protagonist against  the wall,  trying to remember the words of the song.
  202.      Our hero  is normally  OK; if  something went  terribly  wrong  with  the
  203.      rehearsals (e.g.  a dinosaur got sucked through a five-dimensional space-
  204.      time vortex  stretched between  the middle  terrasic to five minutes into
  205.      rehersals; the dinosaur a little off balance after the trip puts down its
  206.      left foot,  and 'crunch'...),  it might be Dead, in which case we have to
  207.      call the  whole thing  off.   We'll call  this scene  'Should  Be  Gently
  208.      Humming'...
  209.  
  210.        Should-Be-Gently-Humming:
  211.            (--) Ok                                 -> Something-Happened
  212.                  + Wait-For-A-Punter
  213.            (--) Dead                               ->
  214.                  + Stop-The-Programme
  215.  
  216.        The coke  machine has  been waiting,  perhaps for days, for a punter to
  217.      come along.   When  the footprints  fade in  from the  distance  (a  coke
  218.      machine's ears  are always  against the  ground, which  explains why  you
  219.      rarely find  coke machines  on wet  or dirty surfaces), the machine hears
  220.      either a cashy 'clink' or a more sinister 'clunk':
  221.  
  222.        Something-Happened:
  223.            (--) Clink                              -> Before-Cooperating
  224.                  + Accept-Punter's-Cash
  225.                  + Wait-For-Punter's-Choice
  226.                  + Shall-We-Cooperate?
  227.            (--) Clunk                              ->
  228.                  + Exit-Stage-Left-Running
  229.                  + Stop-The-Programme
  230.  
  231.        The advent  of a  'Clunk' tells  the machine to beat it, smartly.  If a
  232.      'Clink' happened,  the machine goes on to think about a game plan for the
  233.      coming few  minutes.   It accepts whatever spare change the punter has to
  234.      spare, then pounces, metaphorically:
  235.  
  236.        Before-Cooperating:
  237.            (--) Ok                                 -> Cooperate
  238.                  + Consider-Punter's-Choice
  239.            (--) Nasty                              -> Let's-Be-Nasty
  240.                  + Consider-Punter's-Choice
  241.            (--) Play-Dead                          -> Something-Happened
  242.                  + Switch-Off-All-Lights
  243.                  + Wait-Until-Punter-Has-Left
  244.                  + Switch-On-The-Lights
  245.                  + Wait-For-A-Punter
  246.  
  247.        If it's  in a good mood, the machine ejects more or less the drink that
  248.      the punter chose:
  249.  
  250.        Cooperate:
  251.            (--) Coke                               -> Something-Happened
  252.                  + Eject-Can-Of-Coke
  253.                  + Wait-For-A-Punter
  254.            (--) Spring-Water                       -> Something-Happened
  255.                  + Eject-Can-Of-Spring-Water
  256.                  + Wait-For-A-Punter
  257.            (--) Juice                              -> Something-Happened
  258.                  + Eject-Can-Of-Juice
  259.                  + Wait-For-A-Punter
  260.            (--) Sweeto-Sap                         -> Something-Happened
  261.                  + Eject-Can-Of-Sweeto-Sap
  262.                  + Wait-For-A-Punter
  263.            (--) Empty                              ->
  264.                  + Switch-Off-All-Lights
  265.                  + Stop-The-Programme
  266.  
  267.        If the  coke machine's  pretty weak  internal moral  system failed,  it
  268.      supplies the opposite of whatever the punter wanted:
  269.  
  270.        Let's-Be-Nasty:
  271.            (--) Coke                               -> Something-Happened
  272.                  + Eject-Can-Of-Juice
  273.                  + Wait-For-A-Punter
  274.            (--) Spring-Water                       -> Something-Happened
  275.                  + Eject-Can-Of-Sweeto-Sap
  276.                  + Wait-For-A-Punter
  277.            (--) Juice                              -> Something-Happened
  278.                  + Eject-Can-Of-Coke
  279.                  + Wait-For-A-Punter
  280.            (--) Sweeto-Sap                         -> Something-Happened
  281.                  + Eject-Can-Of-Spring-Water
  282.                  + Wait-For-A-Punter
  283.            (--) Empty                              ->
  284.                  + Switch-Off-All-Lights
  285.                  + Stop-The-Programme
  286.  
  287.        This diagram  is a  little complex  for  a  first  example.    Remember
  288.      however, that we are modelling a rich behaviour pattern that took several
  289.      hundreds of  millions of  years to  evolve.   Real  software  is  usually
  290.      developed much  faster, and  should therefore  be much  simpler, only  it
  291.      isn't.
  292.  
  293. --
  294. Pieter A. Hintjens
  295.